{extend name="common@admin_base" /}

{block name="head_extends"}
<script>
    layui.use('table', function(){
        var table = layui.table;

        var useridDOM = $('#id');
        var usernameDOM = $('#name');
        var emailDOM = $('#type');
        //监听单元格编辑
        table.on('edit(qq)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            $.ajax({
                data:data,
                url:"{$_form.qadmin_get_qq_update}",
                method:"post",
                success:function (data) {
                    var d = JSON.parse(data);
                    if (d.msg == 1){
                        layer.msg(d.info);
                    }else{
                        layer.msg(d.info);
                    }
                },
                error:function (err) {
                    console.info(err);
                }
            });
        });


        //刷新按钮点击事件
        $("#search").on('click',function () {
            table.reload('qq', {
                where: { //设定异步数据接口的额外参数，任意设
                    id: useridDOM.val()
                    ,name: usernameDOM.val()
                    ,type:emailDOM.val()
                    //…
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        $('#reflash').on('click',function () {
            table.reload('qq', {
                where: { //设定异步数据接口的额外参数，任意设
                    id: useridDOM.val()
                    ,name: usernameDOM.val()
                    ,type:emailDOM.val()
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        //工具栏监听
        table.on('tool(qq)', function(obj){
            var data = obj.data;
            console.info(data);
            if(obj.event === 'detail'){
                layer.open({
                    id:'id'+data.id,
                    title:'QQ详情',
                    area: ['1000px', '500px'],
                    offset: 't',
                    type: 2,
                    content: ['{$_form.qadmin_get_qq_detail}'+data.id] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                });
            } else if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    $.ajax({
                        url:'{$_form.qadmin_get_qq_del}',
                        data:{
                            id:data.id
                        },
                        method:'post',
                        success:function (data) {
                            obj.del();
                            console.log(data);
                        }
                    });
                    layer.close(index);
                });
            } else if(obj.event === 'enable'){
                j_ajax('{$_form.qadmin_get_qq_update}',{
                    id:data.id
                    ,status:99
                },function (d) {
                    layer.msg(d.info);
                    if (d.msg == 1){
                        table.reload('articles', {
                            where: { //设定异步数据接口的额外参数，任意设
                                id: useridDOM.val()
                                ,groupName: usernameDOM.val()
                                ,status:emailDOM.val()
                            }
                            ,page: {
                                curr: 1 //重新从第 1 页开始
                            }
                        });
                    }
                })
            } else if(obj.event === 'forbidden'){
                j_ajax('{$_form.qadmin_get_qq_update}',{
                    id:data.id
                    ,status:10
                },function (d) {
                    layer.msg(d.info);
                    if (d.msg == 1){
                        table.reload('articles', {
                            where: { //设定异步数据接口的额外参数，任意设
                                id: useridDOM.val()
                                ,groupName: usernameDOM.val()
                                ,status:emailDOM.val()
                            }
                            ,page: {
                                curr: 1 //重新从第 1 页开始
                            }
                        });
                    }
                })
            }
        });
    });
</script>
{/block}
{block name="body"}

<div class="layui-form">
    搜索ID：
    <div class="layui-inline">
        <input class="layui-input" name="id" id="id" autocomplete="off">
    </div>
    菜单名：
    <div class="layui-inline">
        <input class="layui-input" name="name" id="name" autocomplete="off">
    </div>
    类型：
    <div class="layui-inline">
        <select class="layui-input" name="type" id="type" autocomplete="off">
            <option value="" selected>全部</option>
            <option value="1">管理菜单</option>
            <option value="2">前端菜单</option>
        </select>
    </div>
    <button class="layui-btn" data-type="reload" id="search"><span class="layui-icon layui-icon-search"></span>搜索</button>
    <a id="reflash" data-type="reload" class="layui-btn layui-btn-primary"><span class="layui-icon layui-icon-refresh"></span>刷新</a>
</div>
<table class="layui-table" lay-data="{ url:'{$_form.qadmin_get_qq_list}', id:'qq', page: {layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'], groups: 1 }}" lay-filter="qq">
    <thead>
    <tr>
        <!--<th lay-data="{type:'checkbox'}">ID</th>-->
        <th lay-data="{field:'id', minWidth:10, sort: true,width:40}">ID</th>
        <th lay-data="{field:'qq', minWidth:50, sort: true ,width:120}">qq</th>
        <th lay-data="{field:'masterQQ', minWidth:20, sort: true ,width:120}">管理员QQ</th>
        <th lay-data="{field:'code', minWidth:40, sort: true ,width:140}">注册码</th>
        <th lay-data="{field:'start_time', minWidth:100, sort: true,width:70}">开始时间</th>
        <th lay-data="{field:'end_time', minWidth:100, sort: true,width:70}">结束时间</th>
        <th lay-data="{field:'create_time', minWidth:100, sort: true,width:170}">创建时间</th>
        <th lay-data="{field:'update_time', minWidth:100, sort: true,width:170}">更新时间</th>
        <th lay-data="{field:'pay_status', minWidth:20, sort: true ,width:80}">付款状态</th>
        <th lay-data="{field:'activation_state', minWidth:20, sort: true ,width:80}">激活状态</th>
        <th lay-data="{field:'status', minWidth:20, sort: true ,width:80}">状态</th>
        <th lay-data="{fixed: 'right', align:'center', toolbar: '#tool',width:170}">操作</th>
    </tr>
    </thead>
</table>

<script type="text/html" id="tool">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail" id="{{d.id}}">查看</a>
    {{#  if(d.status == 99){ }}
    <a class="layui-btn layui-btn-xs" lay-event="forbidden" id="{{d.id}}">禁用</a>
    {{#  } else { }}
    <a class="layui-btn layui-btn-xs layui-bg-gray" lay-event="enable" id="{{d.id}}">启用</a>
    {{#  } }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" id="{{d.id}}">删除</a>
</script>
{/block}